// nxtremote.cpp : main project file.

#include <string>
#include <iostream>
#include "bluetooth.h"
#include "motor.h"

int detect_bt_devices();

int main(int argc, char* argv[])
{
   //detect_bt_devices();

   Bluetooth bt;
	bt.connect(6);

	std::cout << "Connected" << std::endl;
   std::cout << "Run program, then press enter" << std::endl;

   int dummy;
   std::cin >> dummy;

	//Motor m(OUT_B,&bt);

	//m.on(100);

	//Sleep(2000);

	//m.off();

   unsigned char msg[] = {0,100};
	bt.send(msg, 2);

   // Give NXT a chance to switch form receive to send mode...
   // seen here: http://www.mindstorms.rwth-aachen.de/documents/downloads/doc/version-4.03/pc_nxt_communication.html#14

   //while (true)
   //{
   //   try
   //   {
   //      Sleep(30);
   //      unsigned char receiveBuffer[256];
   //      bt.receive(receiveBuffer, strlen(msg));
   //      std::cout << "Received: " << receiveBuffer << std::endl;
   //   }
   //   catch (exception e)
   //   {}
   //}

	Sleep(5000);

   for(int i=0; i<42; ++i)
   {
      unsigned char msg2[] = {0,0};
      bt.send(msg2, 2);
      Sleep(500);
   }

	bt.disconnect();

    return 0;
}